<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			.modal-content{
				width: 100%;
				border-radius: 20px;
			}
			#bgcolor{
				width: 100%;
				background-color: #ECF0F5;
			}
			.insert {
				width: 100%;
				height: 350px;
				margin: 0 auto;
				text-align: center;
				padding-top: 10px;
				border-radius: 20px;
				background-color: #ECF0F5;
			}
			
			.title {
				font-size: 24px;
				font-weight: bold;
				line-height: 40px;
				margin-bottom: 20px;
			}
			
			.black {
				font-size: 25px;
				float: right;
			}
			
			.main {
				width: 300px;
				text-align: left;
				margin: 0 auto;
			}
			
			.marginLeft {
				margin-left: 45px;
			}
			.inputTitle{
				display: inline-block;
				width: 100px;
				text-align: right;
			}
		</style>
	</head>

	<body>
		<div class="insert">
			<div class="title">
				编辑用户
			</div>
			<div class="main">
				<p><span class="inputTitle">用户权限：</span><input type="text" name="roleid" id="roleid" value=""placeholder="请输入1-3的数字" /></p>
				<p><span class="inputTitle">姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名：</span><input  type="text"  name="username" id="username1"  value=""/></p>
				<p><span class="inputTitle">密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码：</span><input  type="text"  name="password" id="pas"  value=""/></p>
				<p style="margin-left: 30px;"><span class="inputTille">性&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;别：</span><input type="radio" name="Sex" class="Sex1" value="男" class="Sex" checked="checked" />男 <input type="radio" name="Sex" id="Sex2" value="女" class="Sex2" />女</p>
				<p><span class="inputTitle">邮&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;箱：</span> <input type="email" name="email" id="email" value="" /></p>
				<p><span class="inputTitle">电&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;话：</span> <input type="phone" name="phone" id="phone" value="" /></p>
				<p><button style="margin-left: 30px;" data-dismiss="modal">取消</button><button class=" marginLeft change">修改</button><button class=" marginLeft" data-dismiss="modal">返回</button></p>
			</div>
		</div>
		<script type="text/javascript">
			$(function() {
				var table = $('#table_id_example').DataTable();
				var email = localStorage.getItem("key");
				var id = localStorage.getItem("id");
				$.ajax({
					type: "post",
					url: "/getEmail",
					data: {
						email: email
					},
					success: function(data) {
						var response=data['massage'];
						var result=$.parseJSON(response);
						$("#roleid").val(result.Roleid);
						$("#username1").val(result.UserName);
						$("#pas").val(result.Password);
						if(result.Sex == "男") {
									$(".Sex1")[0].checked = true;
								} else {
									$(".Sex2")[0].checked = true;
								}
						$("#email").val(result.Email);
						$("#phone").val(result.Phone);
					}
				});
				
				$(".change").click(function() {
					var id = localStorage.getItem("id");
					var roleid=$("#roleid").val();
					var username = $("#username1").val();
					var sex="";
					if($(".Sex1").checked==true){
						sex="男";
					}
					else{
						sex="女"
					}
					var pas=$("#pas").val();
					var email = $("#email").val();
					var phone = $("#phone").val();
					$.ajax({
						type: "get",
						url: "/user/update",
						data: {
							id:id,
							roleid:roleid,
							username:username,
							pas:pas,
							sex: sex,
							email: email,
							phone: phone
						},
						success: function(data) {
							if(data['code']==0){
								alert("修改成功！");
								table.draw(false);
							}
							else{
								alert("修改失败！");
							}
						}
					});
				});
			});
		</script>
	</body>

</html>